// !双端一致!

// 方法

import { d_uniShowToast, uniShowToast } from './misc';

export function getWindowInfo() {
  return new Promise((resolve) => {
    uni.getSystemInfo({
      //成功获取的回调函数，返回值为系统信息
      success: (res) => {
        resolve(res);
      },
    });
  });
}

export function uniShowLoading(title = '操作中, 请稍后', toMask = true, otherOpt) {
  let opt = {};
  if (title) {
    opt.title = title;
  }
  uni.showLoading({
    ...opt,
    mask: toMask,
    ...otherOpt
  });
}

export function uniHideLoading() {
  return uni.hideLoading();

}

export function originalData(vueInstance) {
  return vueInstance.$options.data();
}

export function failCbObject(title, cb) {
  return {
    fail: (res) => {
      uniHideLoading();
      cb && cb();
      if (title) uniShowToast(title, false);
      console.warn(res);
      return res;
    },
  };
}
